package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "go_default_library",
    srcs = ["main.go"],
    importpath = "k8s.io/kops/dns-controller/cmd/dns-controller",
    visibility = ["//visibility:private"],
    deps = [
        "//dns-controller/pkg/dns:go_default_library",
        "//dns-controller/pkg/watchers:go_default_library",
        "//dnsprovider/pkg/dnsprovider:go_default_library",
        "//dnsprovider/pkg/dnsprovider/providers/aws/route53:go_default_library",
        "//dnsprovider/pkg/dnsprovider/providers/do:go_default_library",
        "//dnsprovider/pkg/dnsprovider/providers/google/clouddns:go_default_library",
        "//pkg/wellknownports:go_default_library",
        "//protokube/pkg/gossip:go_default_library",
        "//protokube/pkg/gossip/dns:go_default_library",
        "//protokube/pkg/gossip/dns/provider:go_default_library",
        "//protokube/pkg/gossip/memberlist:go_default_library",
        "//protokube/pkg/gossip/mesh:go_default_library",
        "//vendor/github.com/prometheus/client_golang/prometheus/promhttp:go_default_library",
        "//vendor/github.com/spf13/pflag:go_default_library",
        "//vendor/k8s.io/client-go/kubernetes:go_default_library",
        "//vendor/k8s.io/client-go/rest:go_default_library",
        "//vendor/k8s.io/component-base/metrics/prometheus/restclient:go_default_library",
        "//vendor/k8s.io/klog/v2:go_default_library",
    ],
)

go_binary(
    name = "dns-controller",
    out = select({
        "@io_bazel_rules_go//go/platform:linux_amd64": "linux-amd64/dns-controller",
        "@io_bazel_rules_go//go/platform:linux_arm64": "linux-arm64/dns-controller",
        "@io_bazel_rules_go//go/platform:darwin_amd64": "darwin-amd64/dns-controller",
    }),
    embed = [":go_default_library"],
    visibility = ["//visibility:public"],
)

load(
    "@io_bazel_rules_docker//container:container.bzl",
    "container_bundle",
    "container_image",
    "container_push",
)

ARCH = [
    "amd64",
    "arm64",
]

[container_image(
    name = "image-%s" % arch,
    architecture = arch,
    base = "@distroless_base_%s//image" % arch,
    cmd = ["/dns-controller"],
    files = [
        "//dns-controller/cmd/dns-controller",
    ],
    stamp = True,
    user = "10001",
) for arch in ARCH]

[container_push(
    name = "push-image-%s" % arch,
    format = "Docker",
    image = ":image-%s" % arch,
    registry = "{STABLE_DOCKER_REGISTRY}",
    repository = "{STABLE_DOCKER_IMAGE_PREFIX}dns-controller",
    tag = "{STABLE_DNS_CONTROLLER_TAG}-%s" % arch,
) for arch in ARCH]

[container_bundle(
    name = "image-bundle-%s" % arch,
    images = {
        "{STABLE_DOCKER_IMAGE_PREFIX}dns-controller:{STABLE_DNS_CONTROLLER_TAG}": "image-%s" % arch,
    },
) for arch in ARCH]

load("//tools:gzip.bzl", "gzip")

[gzip(
    name = "image-bundle-%s.tar.gz" % arch,
    src = "image-bundle-%s.tar" % arch,
) for arch in ARCH]

load("//tools:hashes.bzl", "hashes")

[hashes(
    name = "image-bundle-%s.tar.gz.hashes" % arch,
    src = "image-bundle-%s.tar.gz" % arch,
) for arch in ARCH]
